package cn.tedu.kcircle.security.support.auto;


import cn.tedu.kcircle.passport.api.rpc.PassportRpcApi;
import cn.tedu.kcircle.security.support.filter.JwtAuthorizationFilter;
import cn.tedu.kcircle.security.support.handler.CustomAccessDeniedHandler;
import cn.tedu.kcircle.security.support.handler.CustomAuthenticationEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;

@Configuration
@Import({WebSecurityConfiguration.class})
public class CustomSecurityHandlerAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(AccessDeniedHandler.class)
    public CustomAccessDeniedHandler customAccessDeniedHandler(){
        return new CustomAccessDeniedHandler();
    }
    @Bean
    @ConditionalOnMissingBean(AuthenticationEntryPoint.class)
    public CustomAuthenticationEntryPoint customAuthenticationEntryPoint(){
        return new CustomAuthenticationEntryPoint();
    }
    @Bean
    @ConditionalOnBean(PassportRpcApi.class)
    public JwtAuthorizationFilter authorizationFilter(PassportRpcApi passportRpcApi){
        return new JwtAuthorizationFilter(passportRpcApi);
    }
}
